# -*- coding: utf-8 -*-
# @Software :   PyCharm
# @File     :   forms.py
# @Author   :   zhaolie
# @Contact  :   zhaolie1989@gmail.com
# @Time     :   2019/11/19 2:19 下午
# @Desc     :   None      

# here put the import lib
import re
from django import forms
from operation.models import UserAsk


class AnotherUserForm(forms.ModelForm):
    class Meta:
        model = UserAsk
        fields = ['name', 'mobile', 'course_name']

    def clean_mobile(self):
        mobile = self.cleaned_data['mobile']
        REGEX_MOBILE = "^1[358]\d{9}$|^147\d{8}$|^176\d{8}$"
        p = re.compile(REGEX_MOBILE)
        if p.match(mobile):
            return mobile
        else:
            raise forms.ValidationError('手机号码非法', code='mobile_invalid')
